<?php
     /**************************************************************************************
     * Bookswapp is a web application which allow students to exchange their textbooks
     * It is developed by students of ITE "C. Colamonico" - Sistemi Informativi Aziendali
     * Acquaviva delle Fonti (BA) - Italy
     *
     * Bookswapp is free software; you can redistribute it and/or modify it under
     * the terms of the GNU Affero General Public License version 3 as published by the
     * Free Software Foundation
     *
     * Bookswapp is distributed in the hope that it will be useful, but WITHOUT
     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
     * details.
     *
     * You should have received a copy of the GNU Affero General Public License along 
     * with this program; if not, see http://www.gnu.org/licenses or write to the Free
     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
     * 02110-1301 USA.
     *
     * You can contact ITE "C. Colamonico" with a mailing address at Via Colamonico, 5 
     * 70021 - Acquaviva delle Fonti (BA) Italy, or at email address bookswapp@itccolamonico.it.
     *
     * The interactive user interfaces in original and modified versions
     * of this program must display Appropriate Legal Notices, as required under
     * Section 5 of the GNU Affero General Public License version 3.
     *
     * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
     * these Appropriate Legal Notices must retain the display of the Bookswapp
     * logo and ITE "C. Colamonico" copyright notice. If the display of the logo is not reasonably
     * feasible for technical reasons, the Appropriate Legal Notices must display the words
     * "Copyright ITE C. Colamonico - http://www.itccolamonico.it - 2014. All rights reserved".
     ****************************************************************************************/
?>

<?php

/**
 * This is the model base class for the table "{{user}}".
 * DO NOT MODIFY THIS FILE! It is automatically generated by giix.
 * If any changes are necessary, you must set or override the required
 * property or method in class "User".
 *
 * Columns in table "{{user}}" available as properties of the model,
 * followed by relations of table "{{user}}" available as properties of the model.
 *
 * @property string $id_user
 * @property string $firstname_user
 * @property string $surname_user
 * @property string $username_user
 * @property string $password_user
 * @property string $email_user
 * @property string $zip_user
 * @property string $city_user
 * @property string $district_user
 * @property string $address_user
 * @property string $phone1_user
 * @property string $phone2_user
 * @property string $geo_lat_user
 * @property string $geo_lng_user
 * @property integer $school_verificated_user
 * @property string $date_create_user
 * @property string $date_update_user
 *
 * @property mixed $bswBooks
 * @property Swap[] $swaps
 * @property Swap[] $swaps1
 * @property mixed $bswClassrooms
 */
abstract class BaseUser extends GxActiveRecord {

	public static function model($className=__CLASS__) {
		return parent::model($className);
	}

        /**
	 * @return string the associated database table name
	 */
	public function tableName() {
		return '{{user}}';
	}

        /**
         * @return the active record label (the user friendly name displayed in the views)
         */
	public static function label($n = 1) {
		return Yii::t('app', 'User|Users', $n);
	}

        /**
         *  @returns string|array The name of the representing column/s (array) for the table
         */
	public static function representingColumn() {
		return 'firstname_user';
	}

        /**
	 * @return array validation rules for model attributes.
	 */
	public function rules() {
		return array(
			array('firstname_user, surname_user, username_user, password_user, email_user, zip_user, city_user, district_user, address_user, phone1_user, date_create_user, date_update_user', 'required'),
			array('school_verificated_user', 'numerical', 'integerOnly'=>true),
			array('firstname_user, surname_user, username_user, email_user, district_user', 'length', 'max'=>45),
			array('password_user, city_user, address_user', 'length', 'max'=>60),
			array('zip_user', 'length', 'max'=>5),
			array('phone1_user, phone2_user', 'length', 'max'=>20),
			array('geo_lat_user, geo_lng_user', 'length', 'max'=>12),
			array('phone2_user, geo_lat_user, geo_lng_user, school_verificated_user', 'default', 'setOnEmpty' => true, 'value' => null),
			array('id_user, firstname_user, surname_user, username_user, password_user, email_user, zip_user, city_user, district_user, address_user, phone1_user, phone2_user, geo_lat_user, geo_lng_user, school_verificated_user, date_create_user, date_update_user', 'safe', 'on'=>'search'),
		);
	}

        /**
	 * @return array relational rules.
	 */
	public function relations() {
		return array(
			'bswBooks' => array(self::MANY_MANY, 'Book', '{{bookmark}}(user_id, book_id)'),
			'swaps' => array(self::HAS_MANY, 'Swap', 'seller_user_id'),
			'swaps1' => array(self::HAS_MANY, 'Swap', 'buyer_user_id'),
			'bswClassrooms' => array(self::MANY_MANY, 'Classroom', '{{user_has_classroom}}(user_id, classroom_id)'),
		);
	}

        /**
	 * The pivot model is used by GxActiveRecord::saveWithRelated().
         * @return array list of pivot models for each MANY_MANY relationship. 
	 */
	public function pivotModels() {
		return array(
			'bswBooks' => 'Bookmark',
			'bswClassrooms' => 'UserHasClassroom',
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */        
	public function attributeLabels() {
		return array(
			'id_user' => Yii::t('app', 'Id User'),
			'firstname_user' => Yii::t('app', 'Firstname User'),
			'surname_user' => Yii::t('app', 'Surname User'),
			'username_user' => Yii::t('app', 'Username User'),
			'password_user' => Yii::t('app', 'Password User'),
			'email_user' => Yii::t('app', 'Email User'),
			'zip_user' => Yii::t('app', 'Zip User'),
			'city_user' => Yii::t('app', 'City User'),
			'district_user' => Yii::t('app', 'District User'),
			'address_user' => Yii::t('app', 'Address User'),
			'phone1_user' => Yii::t('app', 'Phone1 User'),
			'phone2_user' => Yii::t('app', 'Phone2 User'),
			'geo_lat_user' => Yii::t('app', 'Geo Lat User'),
			'geo_lng_user' => Yii::t('app', 'Geo Lng User'),
			'school_verificated_user' => Yii::t('app', 'School Verificated User'),
			'date_create_user' => Yii::t('app', 'Date Create User'),
			'date_update_user' => Yii::t('app', 'Date Update User'),
			'bswBooks' => null,
			'swaps' => null,
			'swaps1' => null,
			'bswClassrooms' => null,
		);
	}

        /**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search() {
		$criteria = new CDbCriteria;

		$criteria->compare('id_user', $this->id_user, true);
		$criteria->compare('firstname_user', $this->firstname_user, true);
		$criteria->compare('surname_user', $this->surname_user, true);
		$criteria->compare('username_user', $this->username_user, true);
		$criteria->compare('password_user', $this->password_user, true);
		$criteria->compare('email_user', $this->email_user, true);
		$criteria->compare('zip_user', $this->zip_user, true);
		$criteria->compare('city_user', $this->city_user, true);
		$criteria->compare('district_user', $this->district_user, true);
		$criteria->compare('address_user', $this->address_user, true);
		$criteria->compare('phone1_user', $this->phone1_user, true);
		$criteria->compare('phone2_user', $this->phone2_user, true);
		$criteria->compare('geo_lat_user', $this->geo_lat_user, true);
		$criteria->compare('geo_lng_user', $this->geo_lng_user, true);
		$criteria->compare('school_verificated_user', $this->school_verificated_user);
		$criteria->compare('date_create_user', $this->date_create_user, true);
		$criteria->compare('date_update_user', $this->date_update_user, true);

		return new CActiveDataProvider($this, array(
			'criteria' => $criteria,
		));
	}
}